package democompare;

public class Student implements Comparable<Student>{
    String name;
    int age;
    Student(String name, int age) {
        this.name = name;
        this.age = age;
    }


    //我们使用了Comparable接口，那么就要重写里面的抽象方法compareTo
    public int compareTo(Student o) {
        //比较学生的年龄
        if(this.age > o.age) {
            return 1;
        } else if(this.age == o.age) {
            return 0;
        } else {
            return -1;
        }
    }

}
